﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System;
using System.ComponentModel;
using System.Windows;

#endregion

namespace Majesty_of_Omega.GUI.Pages.Game.Research.Parts
{
    /// <summary>
    /// Interaktionslogik für "ResearchPointPart.xaml"
    /// </summary>
    public partial class ResearchPointPart : INotifyPropertyChanged
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ResearchPointPart"/> class.
        /// </summary>
        public ResearchPointPart()
        {
            InitializeComponent();
        }

        #region Dependency Property  AppliedResearch

        /// <summary>
        /// Dependency property AppliedResearch
        /// </summary>
        public static readonly DependencyProperty AppliedResearchProperty =
            DependencyProperty.Register("AppliedResearch",
                                        typeof (int),
                                        typeof (ResearchPointPart),
                                        new UIPropertyMetadata(50,
                                                               (d, e) =>
                                                               NotifyPropertyChanged(d, "AppliedResearchPercentage")));


        /// <summary>
        /// Gets or sets the AppliedResearch
        /// </summary>
        /// <value>The value.</value>
        public int AppliedResearch
        {
            get { return (int) GetValue(AppliedResearchProperty); }
            set { SetValue(AppliedResearchProperty, value); }
        }

        #endregion

        #region Dependency Property  FundamentalResearch

        /// <summary>
        /// Dependency property FundamentalResearch
        /// </summary>
        public static readonly DependencyProperty FundamentalResearchProperty =
            DependencyProperty.Register("FundamentalResearch",
                                        typeof (int),
                                        typeof (ResearchPointPart),
                                        new UIPropertyMetadata(50,
                                                               (d, e) =>
                                                               NotifyPropertyChanged(d, "FundamentalResearchPercentage")));


        private static void NotifyPropertyChanged(DependencyObject d, string property)
        {
            ResearchPointPart part = (ResearchPointPart) d;
            part.InvokePropertyChanged(property);
        }


        /// <summary>
        /// Gets or sets the FundamentalResearch
        /// </summary>
        /// <value>The value.</value>
        public int FundamentalResearch
        {
            get { return (int) GetValue(FundamentalResearchProperty); }
            set { SetValue(FundamentalResearchProperty, value); }
        }

        #endregion

        /// <summary>
        /// Gets the applied research in percent
        /// </summary>
        /// <value>The applied research percentage.</value>
        public int AppliedResearchPercentage
        {
            get { return Convert.ToInt32(((double) AppliedResearch)/(AppliedResearch + FundamentalResearch)*100.0); }
        }

        /// <summary>
        /// Gets the fundamental research in percent
        /// </summary>
        /// <value>The fundamental research percentage.</value> 
        public int FundamentalResearchPercentage
        {
            get { return 100 - AppliedResearchPercentage; }
        }

        /// <summary>
        /// Notify wpf, that a data bound property has changed
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;


        /// <summary>
        /// Notify wpf, that a databound property has changed
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        internal void InvokePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}